using System;

namespace Framework
{
    public class Bit32
    {
        public int Value;

        public int Set(int index, bool value)
        {
            if (value)
            {
                Value = Open(Value, index);
            }
            else
            {
                Value = Close(Value, index);
            }
            return Value;
        }
        public bool Get(int index)
        {
            return Any(Value, index);
        }
        public static int Open(int value, int index)
        {
            if (index < 0 || index > 31)
            {
                throw new Exception("index value must be [0-31]");
            }
            return value | 1 << index;
        }
        public static int Close(int value, int index)
        {
            if (index < 0 || index > 31)
            {
                throw new Exception("index value must be [0-31]");
            }
            return value & ~(1 << index);
        }
        public static bool All(int value, int search)
        {
            return (value & search) == search;
        }
        public static bool Any(int value, int search)
        {
            return (value & search) != 0;
        }
    }
}